package main

import (
	"context"
	"fmt"
	"git.medlinker.com/golang/ka"
	"github.com/Shopify/sarama"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	ka.SetVersion(sarama.V0_11_0_0)
	cfg := new(ka.ConsumerConfig)
	cfg.Brokers = []string{"dts-cn-hangzhou.aliyuncs.com:18001"}
	cfg.Topic = "cn_hangzhou_i_bp19ibpdra8ue58x6byp_3306_daipei"
	cfg.Group = "dtsrrrd1ys5a8y2b46"
	cfg.SASL.Enable = true
	cfg.SASL.User = "tmpacc-dtsrrrd1ys5a8y2b46"
	cfg.SASL.Password = "tmptest314"

	consumer, err := ka.NewConsumer(cfg)
	if err != nil {
		panic(err)
	}
	consumer.HandleTopic(func(ctx context.Context, e *ka.Event) error {
		fmt.Println(e)
		return nil
	})
	consumer.HandleError(func(e error) {
		fmt.Println("error", e)
	})
	consumer.Run()
	defer consumer.Close()

	exit := make(chan os.Signal, 1)
	signal.Notify(exit, syscall.SIGTERM, syscall.SIGINT)
	<-exit
}
